import CKYRequest from './request'
import { BASE_URL, TIME_OUT } from './request/config'

import localeCache from '@/untils/cache'

const ckyRequest = new CKYRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  headers: {},
  interceptors: {
    requestInterceptor: (config) => {
      // 携带token的拦截
      const token = localeCache.getCache('token')
      if (token && config.headers) {
        config.headers.Authorization = `Bearer ${token}`
      }
      return config
    },
    requestInterceptorCatch: (err) => {
      return err
    },
    respondInterceptor: (res) => {
      return res
    },
    respondInterceptorCatch: (err) => {
      return err
    }
  }
})

export default ckyRequest
